package structures;

/**
 * @ClassName: Test$
 * @Description: java类作用描述
 * @Author: xinya
 * @CreateDate: 2020/12/18$ 19:50$
 * @UpdateRemark: 更新内容
 * @Version: 1.0
 */
public class Test {
    public static void main(String[] args) {
        Person lisi = new Person("lisi", 24);
        Person lisi2 = (Person) lisi.clone();
        System.out.println(lisi);
        System.out.println(lisi2);
        lisi2.setName("wangwu");
        System.out.println(lisi);
        System.out.println(lisi2);
    }
}


class Person implements Cloneable {
    private String name;
    private int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public Object clone() {
        try {
            return super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
